import 'package:flutter/material.dart';

class ResponsiveUtil {
  static late MediaQueryData _mediaQueryData;
  static late double screenWidth;
  static late double screenHeight;

  static void init(BuildContext context) {
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData.size.width;
    screenHeight = _mediaQueryData.size.height;
  }

  static double width(double percent) => screenWidth * percent / 100;
  static double height(double percent) => screenHeight * percent / 100;
  
  static double fontSize(double baseSize) {
    final double scaleFactor = screenWidth / 375; // 以375作为基准宽度
    return baseSize * scaleFactor.clamp(0.8, 1.2);
  }

  static EdgeInsets getPadding({
    double horizontalPercent = 0,
    double verticalPercent = 0,
  }) {
    return EdgeInsets.symmetric(
      horizontal: width(horizontalPercent),
      vertical: height(verticalPercent),
    );
  }
}